/**
 * =============================================================================
 * ************   Select 下拉选择   ************
 * =============================================================================
 */

.mdui-select {
  font-family: @font-family-base;
  display: inline-block;
  box-sizing: border-box;
  vertical-align: middle;
  position: relative;
  padding-left: 0;
  padding-right: 24px;
  appearance: none;
  height: 36px;
  max-width: 100%;
  border: none;
  cursor: pointer;
  outline: none;
  font-size: 16px;
  user-select: none;

  will-change: background-color, box-shadow, background-position-x;
  transition-property: background-color, box-shadow, background-position-x;
  transition-duration: .2s;
  transition-timing-function: @animation-curve-default;

  border-bottom: 1px solid rgba(0, 0, 0, 0.12);

  &.mdui-select-open {
    border-bottom: none;
  }

  // 箭头
  background-repeat: no-repeat;
  background-position: right center;
  background-image: data-uri('image/svg+xml', './select/svg/arrow_down_dark.svg');
}

.mdui-select-position-top {
  background-image: data-uri('image/svg+xml', './select/svg/arrow_up_dark.svg');
}

/* 底部和顶部菜单的样式 */
.mdui-select-open {
  &.mdui-select-position-top,
  &.mdui-select-position-bottom {
    border-radius: 2px;
    background-color: #fff;
    background-position-x: calc(~'100% - 12px');
    z-index: 99999;
  }

  &.mdui-select-position-top {
    border-top-left-radius: 0;
    border-top-right-radius: 0;
    border-top: 1px solid rgba(0, 0, 0, 0.12);
    border-bottom: 2px solid transparent;
    box-shadow: 0 10px 10px -3px rgba(0,0,0,.2), 0 0px 14px 1px rgba(0,0,0,.14), 0 -7px 24px 2px rgba(0,0,0,.12);

    .mdui-select-menu {
      border-bottom-left-radius: 0;
      border-bottom-right-radius: 0;

      // 隐藏下方的阴影
      box-shadow: 0px -4px 4px -2px rgba(0,0,0,.06), 8px 0 8px -4px rgba(0,0,0,.12), -8px 0 8px -4px rgba(0,0,0,.12)
    }
  }

  &.mdui-select-position-bottom {
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
    border-bottom: 1px solid rgba(0, 0, 0, 0.12);
    .mdui-shadow(8);

    .mdui-select-menu {
      border-top-left-radius: 0;
      border-top-right-radius: 0;

      // 隐藏上方阴影
      box-shadow: 0 5px 5px -3px rgba(0,0,0,.2), 0 9px 9px 1px rgba(0,0,0,.14), 0px 8px 8px 2px rgba(0,0,0,.06);
    }
  }
}

/* 当前选中项文本 */
.mdui-select-selected {
  display: block;
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  left: 0;
  right: 24px;
  .mdui-text-truncate();

  transition: left .2s @animation-curve-linear-out-slow-in;

  .mdui-select-open & {
    left: 16px;
    right: 32px;
  }

  .mdui-select-open.mdui-select-position-auto & {
    visibility: hidden;
  }
}

/* 菜单 */
.mdui-select-menu {
  position: relative;
  box-sizing: border-box;
  margin: 0 -24px 0 0;
  border-radius: 2px;
  background-color: #fff;
  color: @color-black-text;
  z-index: 99999;
  height: 36px;
  visibility: hidden;
  .mdui-shadow(8);
  opacity: 0;
  cursor: default;
  transform: scale(1, 0);

  // 在计算宽度时，把滚动条计算进去
  overflow-y: scroll;
  -webkit-overflow-scrolling: touch;

  will-change: transform, opacity, visibility;
  transition-property: transform, opacity, visibility;
  transition-duration: .2s;
  transition-timing-function: @animation-curve-linear-out-slow-in;

  // 打开状态的菜单
  .mdui-select-open & {
    opacity: 1;
    transform: scale(1, 1);
    visibility: visible;
    overflow-y: hidden;
  }

  // 关闭状态的菜单
  .mdui-select-closing & {
    visibility: visible;
    overflow-y: hidden;
    transform: scale(1, 1);
    opacity: 0;
    box-shadow: none;
  }
}

/* 菜单项 */
.mdui-select-menu-item {
  height: 48px;
  line-height: 48px;
  padding: 0 16px;
  cursor: pointer;
  .mdui-text-truncate();

  &:hover {
    background-color: @color-grey-200;
  }

  &:first-child {
    margin-top: 8px;
  }

  &:last-child {
    margin-bottom: 8px;
  }

  // 禁用项
  &[disabled] {
    cursor: default;
    color: @color-black-disabled !important;

    &:hover {
      background-color: inherit !important;
    }
  }

  // 已选中项
  &[selected] {
    color: @color-default-a200;
  }
}


/* 原生 select 组件 */
select.mdui-select {
  background-color: transparent;

  option {
    color: rgba(0, 0, 0, 0.87);
  }

  // 移除 IE 的下拉按钮
  &::-ms-expand {
    display: none;
  }
}

/* 原生多选 select 组件 */
select.mdui-select[multiple] {
  border: 1px solid rgba(0, 0, 0, 0.38);
  padding: 0;
  height: auto;
  cursor: default;
  font-size: 15px;
  background-color: #FFFFFF;
  background-image: none;

  optgroup {
    margin: 8px 0 0 0;
    padding: 0 0 0 16px;
    color: rgba(0, 0, 0, 0.38);

    &:last-child {
      margin-bottom: 8px;
    }

    &:not(:first-child) {
      padding-top: 8px;
      border-top: 1px solid rgba(0, 0, 0, 0.12);
    }
  }

  option {
    margin: 0 0 0 -16px;
    padding: 0 16px;
    height: 32px;
    display: flex;
    align-items: center;
    color: rgba(0, 0, 0, 0.87);

    &:first-child {
      margin-top: 8px;
    }

    &:last-child {
      margin-bottom: 8px;
    }
  }
}

/**
 * =============================================================================
 * ************   Select 强调色   ************
 * =============================================================================
 */

& {
  .loop-accent-theme(@counter-color) when (@counter-color > 0) {
    .loop-accent-theme((@counter-color - 1));
    @colorName: extract(@globalAccentColors, @counter-color);

    .mdui-theme-accent-@{colorName} {

      .mdui-select-menu-item {
        // 菜单中已选中项
        &[selected] {
          .mdui-text-color(@colorName);
        }
      }

    }
  }
  .loop-accent-theme(length(@globalAccentColors));
}


/**
 * =============================================================================
 * ************   Select dark   ************
 * =============================================================================
 */
.mdui-theme-layout-dark when (@globalLayoutDark = true) {
  .mdui-select {
    border-bottom: 1px solid rgba(255, 255, 255, 0.12);
    background-image: data-uri('image/svg+xml', './select/svg/arrow_down_light.svg');
  }

  .mdui-select-position-top {
    background-image: data-uri('image/svg+xml', './select/svg/arrow_up_light.svg');
  }

  .mdui-select-open {
    &.mdui-select-position-top,
    &.mdui-select-position-bottom {
      background-color: @layout-dark-color-4;
    }

    &.mdui-select-position-top {
      border-top: 1px solid rgba(255, 255, 255, 0.12);
    }

    &.mdui-select-position-bottom {
      border-bottom: 1px solid rgba(255, 255, 255, 0.12);
    }
  }

  .mdui-select-menu {
    background-color: @layout-dark-color-4;
    color: #fff;
  }

  .mdui-select-menu-item {
    &:hover {
      background-color: @color-grey-700;
    }

    &[disabled] {
      color: @color-white-disabled !important;
    }
  }

  // 原生 select 组件
  select.mdui-select {
    background-color: @layout-dark-color-3;
    color: #FFFFFF;

    option {
      background-color: @layout-dark-color-3;
      color: #FFFFFF;
    }
  }

  // 原生多选 select 组件
  select.mdui-select[multiple] {
    border: 1px solid rgba(255, 255, 255, 0.5);

    optgroup {
      color: rgba(255, 255, 255, 0.5);

      &:not(:first-child) {
        border-top: 1px solid rgba(255, 255, 255, 0.12);
      }
    }
  }
}
